<template>
  <div class="fangyuan">
    <h1>房源管理</h1>
    <!-- 模糊 -->
    <el-button type="primary" @click="recommend">推荐</el-button>
    <el-button type="primary" @click="nrecommend">不推荐</el-button>
    <el-form :inline="true" :model="pageInfo" class="demo-form-inline">
      <el-form-item>
        <el-select v-model="pageInfo.rstatus" placeholder="请选择出租状态">
          <el-option label="请选择出租状态" value=""></el-option>
          <el-option label="待租中" value="0"></el-option>
          <el-option label="已出租" value="1"></el-option>
          <el-option label="维修中" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="pageInfo.publishStatus" placeholder="请选择发布状态">
          <el-option label="请选择发布状态" value=""></el-option>
          <el-option label="未发布" value="0"></el-option>
          <el-option label="已发布" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="请输入楼盘关键字">
        <el-input v-model="pageInfo.name" placeholder="请输入楼盘关键字"></el-input>
      </el-form-item>
      <el-form-item label="请输入房源关键字">
        <el-input v-model="pageInfo.roomName" placeholder="请输入房源关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        prop="id"
        label="id"
        width="120">
      </el-table-column>
      <el-table-column label="id" width="120">
        <template slot-scope="scope">
          <el-image :src="scope.row.frontCover"></el-image>
        </template>
      </el-table-column>
      <el-table-column
        prop="roomName"
        label="房源名称"
        width="120">
      </el-table-column>
      <el-table-column
        prop="name"
        label="楼盘名称"
        width="120">
      </el-table-column>
      <el-table-column
        prop="roomCode"
        label="房源编号"
        width="120">
      </el-table-column>
      <el-table-column
        prop="proportion"
        label="面积"
        width="120">
      </el-table-column>
      <el-table-column
        prop="rental"
        label="租金"
        width="120">
      </el-table-column>
      <el-table-column label="出租状态" width="120">
        <template slot-scope="scope">
          {{scope.row.status==0?"待租中":scope.row.status==1?"已出租":"维修中"}}
        </template>
      </el-table-column>
      <el-table-column
        prop="username"
        label="发布人"
        width="120">
      </el-table-column>
      <el-table-column label="发布状态" width="120">
        <template slot-scope="scope">
          {{scope.row.publishStatus==0?"未发布":"已发布"}}
        </template>
      </el-table-column>
      <el-table-column label="是否推荐" width="120">
        <template slot-scope="scope">
          {{scope.row.recommended==2?"已推荐":"未推荐"}}
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
background
layout="prev, pager, next"
      :page-size="pageInfo.pageSize"
      :total="pageInfo.total"
      :page-count="pageInfo.pageCount"
      :current-page="pageInfo.pageNum"
      @current-change="pageChange"
    >
    </el-pagination>
  </div>
</template>
<script>
import axios from 'axios'

export default {
  created() {
    this.housingList()
  },
  data() {
    return {
      tableData: [],
      multipleSelection: {
        recommended:'',
        id:''
      },
      pageInfo:{
        pageCount:10,
        pageSize:10,
        total:1,
        pageNum:1,
        name:'',
        roomName:'',
        status:'',
        publishStatus:''
      }
    }
  },
  methods: {
    onSubmit(){
      this.pageInfo.pageNum = 1
      this.housingList()
    },
    pageChange(val){
      this.pageInfo.pageNum = val
      this.housingList()
    },
    handleSelectionChange(vals) {
      for (let val of vals) {
        this.multipleSelection.recommended = val.recommended
        this.multipleSelection.id = val.id
      }

    },
    housingList(){
      axios.post("http://localhost:8200/hou/TbRoomInfoController/list",this.pageInfo).then(res=>{
        this.tableData = res.data.obj.records

        this.pageInfo.pageSize = res.data.obj.size
        this.pageInfo.total = res.data.obj.total
        this.pageInfo.pageCount = res.data.obj.pages
        this.pageInfo.pageNum = res.data.obj.current
      })
    },
    recommend() {
      if (this.multipleSelection.id == "") {
        this.$alert('请选择一条数据')
      } else {
        axios.post('http://localhost:8200/hou/TbRoomInfoController/recommend',this.multipleSelection).then((res) => {
          if (res.data.obj) {
            alert("操作成功")
            this.multipleSelection = {}
            this.housingList()
          }
        })
      }
    },
    nrecommend() {
      if (this.multipleSelection.id == "") {
        this.$alert('请选择一条数据')
      } else {
        axios.post('http://localhost:8200/hou/TbRoomInfoController/nrecommend',this.multipleSelection).then((res) => {
          if (res.data.obj) {
            alert("操作成功")
            this.multipleSelection = {}
            this.housingList()
          }
        })
      }
    }
  }
}
</script>

